define([
	'angular',
	'angularUiRouter',    
	'uiRouterExtras',
    'ocLazyLoad',
    'ngFileUpload',
    ],
	function() {
		angular.module('gbits.websns.kernelApp', ['ui.router', 'oc.lazyLoad', 'ct.ui.router.extras',])
		.controller('RootController',[
		    '$scope', 
		    '$state',
		    function($scope, $state) {
		    	$scope.errorMsg = function(data) {
		    		alert(data.message);
		    	}
		    	
		    	
		    }
	    ])	   	   
		.config(function($stateProvider, $futureStateProvider, $ocLazyLoadProvider) {			
			// Set the app module as loaded
		    $ocLazyLoadProvider.config({
		        loadedModules: ['gbits.websns.kernelApp'],
		        debug: false,
		        jsLoader: requirejs,
		    });
		    
		    // Future state factory
		    $futureStateProvider.stateFactory('ocLazyLoad', function($q, $ocLazyLoad, futureState) {
		        var deferred = $q.defer();

		        $ocLazyLoad.load(futureState.load).then(function() {
		        	deferred.resolve();
		        }, function() {
		        	deferred.reject();
		        });

		        return deferred.promise;
		    });
		    
		    // The future (lazy loaded) states of the application
		    var futureStates = [{
		        type: 'ocLazyLoad',
		        stateName: 'kernel.appList.dashboard',
		        urlPrefix: '/dashboard',
		        load: [{
		        	name: 'gbits.websns.appList',
		        	reconfig: true,
		        	files: [appBasePath + '/app-center/app.js']
		        }]
		    },{
		    	type: 'ocLazyLoad',
		        stateName: 'kernel.appList.substance',
		        urlPrefix: '/substance',
		        load: [{
		        	name: 'gbits.websns.substance',
		        	reconfig: true,
		        	files: [appBasePath + '/scripts/app.js']
		        }]
		    }];
		    angular.forEach(futureStates, function (fstate) {
		    	$futureStateProvider.futureState(fstate);
	        });
		    
		    $stateProvider		    	        
	        .state('kernel', { // 平台入口页为核心框架主页
	        	url: '/',
	        	templateUrl: appBasePath + '/kernel/view/kernel.html',
	        	controller:'KernelController',
	        	resolve: {
	                load: ['$ocLazyLoad', 
	                    function($ocLazyLoad) {
	                		return $ocLazyLoad.load({
	                			name:'gbits.websns.kernel',
	            				files:[
	        					 	appBasePath + '/kernel/controller/KernelController.js',
	    					 	]}
	        				);
	                	}
	                ]
	            }
	        })	        
	    	.state('kernel.appList', {
			    url:'appList',
			    templateUrl: appBasePath + '/app-center/view/index.html',
				resolve: {
			        load: ['$ocLazyLoad',
			            function($ocLazyLoad) {
			        		return $ocLazyLoad.load({
			        			name:'gbits.websns.appList',
			        			files: [
			    			        appBasePath + '/app-center/controller/MainController.js',                			        
						        ]
			        		});
			        	}
			        ],                   
			    },
			    controller:'AppList.MainController'
			});
		}).run(['$state', '$rootScope', '$http', '$timeout', '$location',
	        function($state, $rootScope, $http, $timeout, $location){
			
		}]);
	}
);